#ifndef DATABASE_H
#define DATABASE_H
// Database.h
#include <vector>
#include <iostream>
#include "database/Db.h"
#include "transaction/Transaction.h"
#include <shared_mutex>
#include <memory>
#include <stack>

class Database {
public:
    // constructor taking row number of database (100)
    explicit Database(int numRows);
    // execute vector of transactions, LESSON: passed by ref to avoid performance overhead of copying, const to avoid modification
    void executeTransactions(const std::vector<Transaction>& transactions);

    void run(const std::vector<Transaction>& transactions);

private:
    std::unique_ptr<Db> db; // database with 100 rows
    std::unique_ptr<std::vector<std::shared_mutex>> rowReadLocks;
    std::unique_ptr<std::vector<std::shared_mutex>> rowWriteLocks;
    
    //stack for storing the locks acquired by the transaction, first in first out so the lock acquired in the earlier transaction is released first
    std::stack<int> readLocksAcquired;
    std::stack<int> writeLocksAcquired;
};

#endif